package com.linzelin.dao;

import com.linzelin.po.Blog;
import com.linzelin.utils.IDUtils;
import com.linzelin.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.*;

public class Mytest {
    @Test
    public void addBlog(){
        try(SqlSession sqlSession = MyBatisUtils.getSqlSession()){
            BlogMapper mapper = sqlSession.getMapper(BlogMapper.class);
            Map<String,Object> map = new HashMap();
            //map.put("author","lin");
            //map.put("title","我爱中国");
            map.put("views",3000);
            List<Blog> blogs = mapper.queryBlogChoose(map);
            for (Blog blog : blogs) {
                System.out.println(blog);
            }
        }
    }

    @Test
    public void updateBlog(){
        try(SqlSession sqlSession = MyBatisUtils.getSqlSession()){
            BlogMapper mapper = sqlSession.getMapper(BlogMapper.class);
            Map<String,Object> map = new HashMap();
            map.put("author","li");
            map.put("title","我sda中国");
            map.put("id","1");
            int i = mapper.updateBlog(map);

        }
    }

    @Test
    public void queryBlogForeach(){
        try(SqlSession sqlSession = MyBatisUtils.getSqlSession()){
            BlogMapper mapper = sqlSession.getMapper(BlogMapper.class);
            Map map = new HashMap();
            List<Integer> list = new ArrayList<>();
            list.add(1);
            //list.add(2);
            //list.add(3);
            map.put("ids",list);
            List<Blog> blogs = mapper.queryBlogForeach(map);
            System.out.println(blogs);
        }
    }
}
